using Microsoft.EntityFrameworkCore;
using PetAdoptApi.Entity;

namespace PetAdoptApi.Database;


public class AppDbContext : DbContext
{
    public AppDbContext(DbContextOptions<AppDbContext> ops) : base(ops) { }
    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
    {
        base.OnConfiguring(optionsBuilder);
        optionsBuilder.UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking);
#if DEBUG
        optionsBuilder.LogTo(Console.WriteLine);
#endif
    }

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        base.OnModelCreating(modelBuilder);
        modelBuilder.Entity<UserFavorite>().HasKey(uf => new { uf.UserId, uf.PetId });
        modelBuilder.Entity<Pet>().HasData(InitialPetData);
    }

    public virtual DbSet<User> Users { get; set; } = default!;
    public virtual DbSet<Pet> Pets { get; set; } = default!;
    public virtual DbSet<UserFavorite> UserFavorites { get; set; } = default!;
    public virtual DbSet<UserAdoption> UserAdoptions { get; set; } = default!;


    private List<Pet> InitialPetData =
    [
        new Pet{Id =1,Name ="Bob",Breed = "Dog-Golden Retrever",Price = 300, Description ="This is a cute dog,and easy to come along with!",Image = "/image/a.jpg"},
        new Pet{Id =2,Name ="Bob 2",Breed = "Dog-Golden Retrever",Price = 300, Description ="This is a cute dog,and easy to come along with!",Image = "/image/a.jpg"},
        new(){Id =3,Name ="Bob 3",Breed = "Dog-Golden Retrever",Price = 300, Description ="This is a cute dog,and easy to come along with!",Image = "/image/a.jpg"},
        new Pet{Id =4,Name ="Bob 4",Breed = "Dog-Golden Retrever",Price = 300, Description ="This is a cute dog,and easy to come along with!",Image = "/image/a.jpg"},
        new Pet{Id =5,Name ="Bob 5",Breed = "Dog-Golden Retrever",Price = 300, Description ="This is a cute dog,and easy to come along with!",Image = "/image/a.jpg"},
        new Pet{Id =6,Name ="Bob 6" ,Breed = "Dog-Golden Retrever",Price = 300, Description ="This is a cute dog,and easy to come along with!",Image = "/image/a.jpg"},
        new Pet{Id =7,Name ="Bob 7",Breed = "Dog-Golden Retrever",Price = 300, Description ="This is a cute dog,and easy to come along with!",Image = "/image/a.jpg"},
        new Pet{Id =8,Name ="Bob 8",Breed = "Dog-Golden Retrever",Price = 300, Description ="This is a cute dog,and easy to come along with!",Image = "/image/a.jpg"},
    ];
}
